package com.ray.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.bean.CompanyMaterialTableBean;
import com.ray.bean.DatatablesViewPageBean;
import com.ray.bean.WarehouseInOutDetailBean;
import com.ray.exception.ServiceException;
import com.ray.service.ReturnWarehouseToProviderService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import com.ray.util.ReturnStringUtil;

/**
 * 仓库退回给供应商的控制层
 * @author libin
 *
 */
@Controller
@RequestMapping("/returnWarehouseToProvider")
public class ReturnWarehouseToProviderController {
	
	@Autowired
	ReturnWarehouseToProviderService returnWarehouseToProviderService;
	
	/**
	 * 获取可退回给客户的物料单
	 * @param request
	 * @return
	 */
	@RequestMapping("/getMaterialCanReturnToProviderData")
	@ResponseBody
	public DatatablesViewPageBean<CompanyMaterialTableBean> getMaterialCanReturnToProviderData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		return returnWarehouseToProviderService.getMaterialCanReturnToProviderData(map);
	}
	
	/**
	 * 生成退回给供应商信息
	 * id (出入库id)
	 * count (退回数量)
	 * inOutMoney (退回金额)
	 * sumMoneyCount 退回计价数量
	 * @param request
	 * @return
	 * @throws CloneNotSupportedException 
	 */
	@RequestMapping("/AddMateiralToProvider")
	@ResponseBody
	public Map<String,Object> AddMateiralToProvider(HttpServletRequest request) throws CloneNotSupportedException{
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		String message = returnWarehouseToProviderService.AddReturnMaterialToPrivder(map);
		return ResponseUtil.ResponseResult(ReturnStringUtil.OPERATION_SUCCESS+message);
	}
	
	/**
	 * 获取已生成的退货单
	 * @param request
	 * @return
	 */
	@RequestMapping("/getReturnToProviderData")
	@ResponseBody
	public DatatablesViewPageBean<WarehouseInOutDetailBean> getReturnToProviderData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		return returnWarehouseToProviderService.getReturnToProviderData(map);
	}
	
	/**
	 * 审核退货单
	 * @return
	 */
	@RequestMapping("/updateReturnToProviderData")
	@ResponseBody
	public Map<String,Object> updateReturnToProviderData(HttpServletRequest request,int status){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		String message = returnWarehouseToProviderService.updateReturnToProviderData(map,status);
		return ResponseUtil.ResponseResult("审核成功 "+message);
	}
	
	/**
	 * 获取可退回入库的数据
	 * @param requestg
	 * @return
	 */
	@RequestMapping("/getCanInCountByReturnToProviderData")
	@ResponseBody
	public DatatablesViewPageBean<CompanyMaterialTableBean> getCanInCountByReturnToProviderData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		return returnWarehouseToProviderService.getCanInCountByReturnToProviderData(map);
	}
	
	/**
	 * 保存退回入库单
	 * id 
	 * count
	 * inOutMoney
	 * warehouseData
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveInCountByReturnToProviderData")
	@ResponseBody
	public Map<String,Object> saveInCountByReturnToProviderData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		String message = returnWarehouseToProviderService.saveInCountByReturnToProviderData(map);
		return ResponseUtil.ResponseResult("保存成功 "+message);
	}
	
	/**
	 * 查询退回入库单
	 * @param request
	 * @return
	 */
	@RequestMapping("/getInCountByReturnToProvderData")
	@ResponseBody
	public DatatablesViewPageBean<WarehouseInOutDetailBean> getInCountByReturnToProvderData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		return returnWarehouseToProviderService.getInCountByReturnToProvderData(map);
	}
	
	/**
	 * 审核退回入库单
	 * @param request
	 * @return
	 */
	@RequestMapping("/updateInCountByReturnToProvderData")
	@ResponseBody
	public Map<String,String> updateInCountByReturnToProvderData(HttpServletRequest request,int status){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		String message = returnWarehouseToProviderService.updateInCountByReturnToProvderData(map,status);
		return ResponseUtil.ResponseResult("审核成功"+message);
	}
	
	/**
	 * 获取车间退回到仓库,并且能出库给车间的
	 * @param request
	 * @return
	 */
	@RequestMapping("/getCanWorkShopToWarehouseData")
	@ResponseBody
	public DatatablesViewPageBean<WarehouseInOutDetailBean> getCanWorkShopToWarehouseData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		return returnWarehouseToProviderService.getWorkShopToWarehouseData(map);
	}
	
	/**
	 * 保存退回给车间的物料信息
	 * @return
	 */
	@RequestMapping("/saveWorkShopToWarehouseData")
	@ResponseBody
	public Map<String,Object> saveWorkShopToWarehouseData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		String message = returnWarehouseToProviderService.saveWorkShopToWarehouseData(map);
		return ResponseUtil.ResponseResult("保存成功 "+message);
	}
	
	/**
	 * 查询退回给车间的物料信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/getWorkShopToWorkShopData")
	@ResponseBody
	public DatatablesViewPageBean<WarehouseInOutDetailBean> getWorkShopToWorkShopData(HttpServletRequest request){
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		return returnWarehouseToProviderService.getWorkShopToWorkShopData(map);
	} 
	
	/**
	 * 删除返料单
	 * @param request
	 * @return
	 */
	@RequestMapping("/deleteReturnToWorkShop")
	@ResponseBody
	public Map<String,String> deleteReturnToWorkShop(HttpServletRequest request){
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		returnWarehouseToProviderService.deleteReturnToWorkShop(map);
		return ResponseUtil.ResponseResult("删除成功");
	}
	
	@RequestMapping("/updateReturnToWorkShop")
	@ResponseBody
	public Map<String,String> updateReturnToWorkShop(HttpServletRequest request){
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		returnWarehouseToProviderService.updateReturnToWorkShop(map);
		return ResponseUtil.ResponseResult("修改成功");
	}
	
	@RequestMapping("/approvalReturnToWorkShop")
	@ResponseBody
	public Map<String,String> approvalReturnToWorkShop(HttpServletRequest request,int status) throws ServiceException, CloneNotSupportedException{
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		String message = returnWarehouseToProviderService.approvalReturnToWorkShop(map,status);
		return ResponseUtil.ResponseResult("审核成功 "+message);
	}
	
	
	//删除退货入库单
	@RequestMapping("/deleteReturnInFrom")
	@ResponseBody
	public Map<String,String> deleteReturnInFrom(HttpServletRequest request) throws ServiceException, CloneNotSupportedException{
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(returnWarehouseToProviderService.deleteReturnInFrom(map));
	}
	
	
}
